// Compatibility script for older browsers, especially Safari 14.1.3
(function() {
  // Check for Safari version
  function isSafari() {
    return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  }
  
  function getSafariVersion() {
    if (!isSafari()) return null;
    
    var versionMatch = navigator.userAgent.match(/version\/(\d+)/i);
    if (versionMatch && versionMatch[1]) {
      return parseInt(versionMatch[1]);
    }
    return null;
  }
  
  // Add Promise polyfill if needed
  if (!window.Promise) {
    console.warn('Promise not supported, application may not work correctly');
  }
  
  // Add fetch polyfill if needed
  if (!window.fetch) {
    console.warn('Fetch API not supported, application may not work correctly');
  }
  
  // Handle Safari 14 specific issues
  var safariVersion = getSafariVersion();
  if (safariVersion && safariVersion <= 14) {
    console.log('Safari version ' + safariVersion + ' detected, applying compatibility fixes');
    
    // Force reload if we detect the syntax error
    window.addEventListener('error', function(e) {
      if (e.error && e.error.message && 
          e.error.message.includes('Unexpected token') && 
          e.error.message.includes('<')) {
        console.warn('Detected Safari loading error, attempting reload');
      }
    });
  }
})();